<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Api\BaseinitController;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;
class ApiController extends BaseinitController
{
	public function index()
	{
        $openid=$request->input('openid');
        $pageNum=$request->input('page');
        $limit=$request->input('limit');
        $page=$pageNum-1;
        if ($page != 0) {
            $page = $limit * $page;
        }
        $users = DB::table('order')
            ->whereRaw("concat(`teacher`,`account`) like '%".$key."%'")
            ->where($map)
            ->orderBy('id','desc')
            ->offset($page)
            ->take($limit)
            ->get();
        $data = [
            'code' => 0,
            'msg'   => '正在请求中...',
            'count' => $count,
            'data'  => $orders
        ];
        return response()->json($data);
	}
    public function teacherUp()
    {
        $teacher =DB::table('teacher')
            ->where('state',1)
            ->where('recommend',1)
            ->orderBy('uptime','desc')
            ->take(4)
            ->get();
        $data = [
            'code' => 0,
            'msg'   => '正在请求中...',
            'data'  => $teacher
        ];
        return response()->json($data);
    }
	public function courseUp()
	{
        $course =DB::table('course')
            ->leftJoin('teacher', 'course.t_id', '=', 'teacher.id')
            ->where('course.state',1)
            ->where('course.recommend',1)
            ->orderBy('course.uptime','desc')
            ->take(4)
            ->select('course.*', 'teacher.teacher', 'teacher.account')
            ->get();
        $data = [
            'code' => 0,
            'msg'   => '正在请求中...',
            'data'  => $course
        ];
        return response()->json($data);
	}
	public function courseSear()
	{
		$pageNum=$request->input('page');
        $limit=$request->input('limit');
        $page=$pageNum-1;
        if ($page != 0) {
            $page = $limit * $page;
        }
        $course =DB::table('course')
            ->leftJoin('teacher', 'course.t_id', '=', 'teacher.id')
            ->whereRaw("concat(`course`,`account`,`teacher`) like '%".$key."%'")
            ->where($map)
            ->orderBy('course.id','desc')
            ->offset($page)
            ->take($limit)
            ->select('course.*', 'teacher.teacher', 'teacher.account')
            ->get();
        $data = [
            'code' => 0,
            'msg'   => '正在请求中...',
            'count' => $count,
            'data'  => $course
        ];
        return response()->json($data);
	}
}